<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="username">
<input type="checkbox" id="remember">记住用户名
<script>
    var username = document.querySelector('#username');
    var remember = document.querySelector('#remember');
    if (localStorage.getItem('username')){
       username.value = localStorage.getItem('username');
        remember.checked = true;
    }
    remember.addEventListener('change',function () {
        if (this.checked){
            localStorage.setItem('username',username.value);
        }else {
            localStorage.removeItem('username');
        }
    })

</script>
</body>
</html>
